home *** CD-ROM | disk | FTP | other *** search
/ Champak 106 / Vol 106.iso / games / global_r.swf / scripts / __Packages / Chaf.as < prev    next >
Encoding:
Text File  |  2010-04-12  |  3.1 KB  |  98 lines

  1. class Chaf
  2. {
  3.    var position;
  4.    var velocity;
  5.    var angle;
  6.    var frame;
  7.    var frameExp;
  8.    var bExplode;
  9.    var flightTime;
  10.    var bmpChaf;
  11.    var bmpExplode;
  12.    var bmpCanvas;
  13.    var screenPos;
  14.    function Chaf(pos, vel)
  15.    {
  16.       this.position = pos.clone();
  17.       this.velocity = vel.clone();
  18.       this.angle = 0;
  19.       this.frame = 0;
  20.       this.frameExp = 0;
  21.       this.bExplode = false;
  22.       this.flightTime = 90;
  23.       this.bmpChaf = flash.display.BitmapData.loadBitmap("chaf");
  24.       this.bmpExplode = flash.display.BitmapData.loadBitmap("explosion0");
  25.       this.bmpCanvas = Game.bmpShots;
  26.    }
  27.    function getPosition(Void)
  28.    {
  29.       return this.position.clone();
  30.    }
  31.    function step(Void)
  32.    {
  33.       if(!this.bExplode)
  34.       {
  35.          this.angle += 0.5 * Math.random();
  36.          this.velocity.y -= 0.02;
  37.          this.velocity.x *= 0.97;
  38.          this.velocity.y *= 0.97;
  39.          this.position.x += this.velocity.x;
  40.          this.position.y += this.velocity.y;
  41.          this.frame = this.frame + 1;
  42.          this.frame %= 4;
  43.          if(this.flightTime-- <= 0 || this.position.y < 0)
  44.          {
  45.             Game.getInstance().removeChaf(this);
  46.          }
  47.       }
  48.    }
  49.    function draw(leftEdge)
  50.    {
  51.       var _loc4_ = this.position.x - leftEdge + 10 * Math.cos(this.angle);
  52.       var _loc3_ = this.position.y + 5 * Math.sin(this.angle);
  53.       this.screenPos = new flash.geom.Point(_loc4_,_loc3_);
  54.       if(!this.bExplode)
  55.       {
  56.          var _loc2_ = new flash.display.BitmapData(12,12,true,0);
  57.          _loc2_.copyPixels(this.bmpChaf,new flash.geom.Rectangle(0,Math.floor(this.frame / 2) * 6,6,6),new flash.geom.Point(3,3),null,null,true);
  58.          var _loc5_ = new flash.filters.BlurFilter(2,2,2);
  59.          _loc2_.applyFilter(_loc2_,_loc2_.rectangle,new flash.geom.Point(0,0),_loc5_);
  60.          _loc2_.colorTransform(_loc2_.rectangle,new flash.geom.ColorTransform(1,1,1,(this.flightTime + 50) / 90,0,0,0,0));
  61.          this.bmpCanvas.copyPixels(_loc2_,_loc2_.rectangle,new flash.geom.Point(this.screenPos.x - 6,Game.screenH - (this.screenPos.y + 6)),null,null,true);
  62.       }
  63.       else
  64.       {
  65.          _loc4_ = this.position.x - leftEdge + 10 * Math.cos(this.angle);
  66.          _loc3_ = this.position.y + 5 * Math.sin(this.angle);
  67.          this.screenPos = new flash.geom.Point(_loc4_,_loc3_);
  68.          this.drawExplosion(this.screenPos,true);
  69.       }
  70.    }
  71.    function drawExplosion(pos, bRemove)
  72.    {
  73.       var _loc3_ = _root.attachMovie("explosion1","mcExp",_root.getNextHighestDepth());
  74.       _loc3_.gotoAndStop(this.frameExp + 1);
  75.       var _loc4_ = new flash.geom.Matrix();
  76.       _loc4_.translate(pos.x,Game.screenH - pos.y);
  77.       this.bmpCanvas.draw(_loc3_,_loc4_,null,null,null,true);
  78.       _loc3_.removeMovieClip();
  79.       this.frameExp = this.frameExp + 1;
  80.       if(this.frameExp == 17)
  81.       {
  82.          if(bRemove)
  83.          {
  84.             this.onEndDeadAnim();
  85.          }
  86.       }
  87.    }
  88.    function onEndDeadAnim(Void)
  89.    {
  90.       Game.getInstance().removeChaf(this);
  91.    }
  92.    function getDamage(damage)
  93.    {
  94.       Sounds.playSound("explsion");
  95.       this.bExplode = true;
  96.    }
  97. }
  98.